<?php
/**
 * password {Password}
 *  
 * @author Micheal Luthor
 *
 */
X::import('Application.Modles.Command');
class CPassword extends Command {	
	/**
	 * @param string $paramString
	 * @return Password
	 */
	public function parserParamString($paramString){
		$this->arguments[0] = trim($paramString);
		
		return $this;
	}

	/**
	 * Run the action
	 */
	public function run(){
		if ( empty(X::app()->user->account) ){
			$this->result->errno = XErrorCode::NO_PERMISSION;
			$this->result->error = 'No account is prepared.';
			return ;
		}
		
		$db = new Database();
		
		$user = $db ->SqlBuilder
			->select(array('account', 'password'))
			->from(array('user'))
			->where('account='.X::app()->user->account)
			->execute()
			->allResult();
			
		$password = $user[0]['password'];
		
		if ( $password == $this->arguments[0] ){
			X::app()->user->status = XUser::STATUS_ONLINE;
		}
		else {
			$this->result->errno = XErrorCode::WRONG_PASSWORD;
			$this->result->error = 'Wrong account or password.';
		}
		
		return $this;
	}
}